#pragma once

#include "LeaveRequest.h"

#include <iostream>

class Approver
{
public:
    Approver()
    {
        m_successor = nullptr;
    };
    virtual ~Approver() = default;

public:
    virtual void processRequest(LeaveRequest *request)
    {
        if (this->m_successor != nullptr) {
            this->m_successor->processRequest(request);
        }
    };

    void setSuccessor(Approver *successor)
    {
        this->m_successor = successor;
    }

private:
    Approver *m_successor;
};

// 组长审批
class GroupApprover : public Approver
{
public:
    GroupApprover(unsigned int threshold)
    {
        this->m_threshold = threshold;
    };

public:
    void processRequest(LeaveRequest *request)
    {
        std::cout << request->getEmployeeName() << "请假" << request->getLeaveDays() << "天, 组长审批通过!" << std::endl;
        if (request->getLeaveDays() > m_threshold) {
            Approver::processRequest(request);
        }
    }

private:
    unsigned int m_threshold;
};

// 部长审批
class MinisterApprover : public Approver
{
public:
    MinisterApprover(unsigned int threshold)
    {
        this->m_threshold = threshold;
    };

public:
    void processRequest(LeaveRequest *request)
    {
        std::cout << request->getEmployeeName() << "请假" << request->getLeaveDays() << "天, 部长审批通过!" << std::endl;
        if (request->getLeaveDays() > m_threshold) {
            Approver::processRequest(request);
        }
    }

private:
    unsigned int m_threshold;
};

// 总经理审批
class ManagerApprover : public Approver
{
public:
    void processRequest(LeaveRequest *request)
    {
        std::cout << request->getEmployeeName() << "请假" << request->getLeaveDays() << "天, 总经理审批通过!" << std::endl;
    }
};